<template>
  <div class="wrapper">
    <swiper :options="swiperOption" ref="mySwiper">
      <swiper-slide v-for="item of swiperList" :key="item.id">
        <img class="img-swiper" :src="item.url" />
      </swiper-slide>
      <!-- 原点 -->
      <div class="swiper-pagination" slot="pagination"></div>
      
      <!-- 进度条 -->
      <div class="swiper-scrollbar" slot="scrollbar"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeSwiper',
  components: {  
    
  },
  data () {
    return {
      swiperOption: {
        pagination: {
          el: '.swiper-pagination'
        },
        //如果需要前进后退按钮 需要配合html
        //<!-- 左右箭头 -->
        // <div class="swiper-button-prev" slot="button-prev"></div>
        // <div class="swiper-button-next" slot="button-next"></div>
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
        loop: true,
        autoplay: true,
        //speed: 100,
        on: {
          slideChangeTransitionEnd: function(){
            //console.log(this.activeIndex);//切换结束时，告诉我现在是第几个slide
          },
        }
      },
      swiperList: [
        {
          id: '0001',
          url: 'http://img1.qunarzz.com/piao/fusion/1801/1a/94428c6dea109402.jpg_640x200_2cf590d8.jpg'
        },
        {
          id: '0002',
          url: 'http://img1.qunarzz.com/piao/fusion/1802/42/7c92b9a381e46402.jpg_640x200_1cdce2a4.jpg'
        },
        {
          id: '0003',
          url: 'http://img1.qunarzz.com/piao/fusion/1802/51/e78f936a5b404102.jpg_640x200_c14f0b3a.jpg'
        }
      ]
    }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  },
  methods: {
    someSwiperEvent(v) {
      console.log("123");
    }
  },
  mounted() {
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    // console.log(this, this.swiper, this.$refs, this.$refs.mySwiper)
    // this.swiper.slideTo(3, 1000, false)
  }
}
</script>
<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background: #fff
  .wrapper
    overflow: hidden
    width: 100%
    height: 0
    padding-bottom: 31.25%
    background: #eee
    .img-swiper
      width: 100%
</style>